#!/bin/bash
#author: xlp
#20140225
#to display the subimage automatically

DIR_data=`pwd`
cd $DIR_data


#line=`wc listsubmark | awk '{print($1)}'`
tvcolorred=204
tvcolorgreen=205
i=1
ri=2
#FILE=$1
#echo $DIR_data $line $i $tvcolorred
#ls *_OT_*.fit >listmark
rm -rf listmark
ls *ot.txt >listotfile
for otfile in `cat listotfile`
do
	echo $otfile
	if test -s $otfile
	then
		fitfile=`echo $otfile | sed 's/_ot.txt/.fit/g'`
		regfile=`echo $otfile | sed 's/_ot.txt/.reg/g'`
		echo $fitfile
		echo $fitfile >>listmark
		cat $otfile | awk '{print("image;circle("$1","$2",20)")}' >$regfile
	fi
done

#ls *s*.fit  >listmark
rm -rf xds9.sh
for FILE in `cat listmark`
do
	fitfile=$FILE
	echo $fitfile
	regfile=`echo $fitfile | sed 's/.fit/.reg/g'`
	echo "$fitfile -region $regfile -scale zscale ">>xds9.sh
        cd $DIR_data
done
echo "ds9 " >a
cat a xds9.sh | tr '\n' ' ' >xds9.sh1
mv xds9.sh1 xds9.sh

sh xds9.sh &
